<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .tab ul {
        display: flex;
        width: 500px;
        padding: 0;
        margin: 0;
      }

      .tab ul li {
        flex: 1;
        box-sizing: border-box;
        padding: 0;
        height: 45px;
        line-height: 45px;
        list-style: none;
        text-align: center;
        border-top: 1px solid blue;
        border-right: 1px solid blue;
        cursor: pointer;
        user-select: none;
      }

      .tab ul li:first-child {
        border-left: 1px solid blue;
      }

      .tab ul li.active {
        background-color: orange;
      }

      .tab .content {
        width: 500px;
        height: 300px;
        border: 1px solid blue;
        border-top: 0px;
        box-sizing: border-box;
      }

      .content img {
        width: 100%;
        height: 100%;
      }
    </style>
  </head>

  <body>
    <div id="app">
      <div class="tab">
        <ul>
          <!-- @click="currentIndex = index" -->
          <li v-for="(item,index) in list" v-bind:key="item.title" 
          @click="onClick(index)"

          :class="{active: index === currentIndex}">{{item.title}}</li>
       </ul>
        <div class="content"><img :src="list[currentIndex].img" alt=""></div>
      </div>
    </div>
    <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.9/vue.js"></script>
    <script>
      var vm = new Vue({
        el: "#app",
        data: {
          currentIndex: 0,//当前被选中的索引
          list: [{title: "风景",img: "img/01.png"},
                 {title: "维尼熊",img: "img/02.jpg"},
                 {title: "长颈鹿",img: "img/03.jpg"}]
         
        },
        methods: {
          onClick(index){
            this.currentIndex = index;//方法访问data中的数据一定要加this
          }
        },
      });
    </script>
  </body>
</html>